package com.wcs.main;

import com.wcs.db.MySQLControl;
import com.wcs.domain.Book;
import com.wcs.util.URLFecter;
import org.apache.http.client.HttpClient;
import org.apache.http.impl.client.DefaultHttpClient;

import java.util.List;

/**
 * Created by lyx on 2017/11/25.
 */
public class Run {

    public static void main(String[] args) throws Exception {
        //我们要爬取的一个地址，这里可以从数据库中抽取数据，然后利用循环，可以爬取一个URL队列
        String url="http://search.jd.com/Search?keyword=Python&enc=utf-8&book=y&wq=Python&pvid=33xo9lni.p4a1qb";
        //String url="http://blog.csdn.net/fhaohaizi/article/details/78321400";

        //抓取的数据
        List<Book> data= URLFecter.URLParser(url);
        //循环输出抓取的数据
        for (Book book : data) {
            System.out.println("bookID:"+book.getId()+"\t"+"bookName:"+book.getName()+"\t"+"bookPrice:"+book.getPrice());
        }
        //将抓取的数据插入数据库
        MySQLControl.executeInsert(data);

    }

}
